import {
    reqCategoryList,
    reqGetBannerList,
    reqGetFloorList
} from '@/api'

const actions = {
    //发送请求获取到导航栏数据
    async getCategory({
        commit
    }) {
        let result = await reqCategoryList();
        //当响应状态码为200时调用REQ_CATEGORY_LIST
        if (result.code === 200) {
            commit('REQ_CATEGORY_LIST', result.data);
        }
    },

    //获取banner图片
    async getBannerList({
        commit
    }) {
        let result = await reqGetBannerList();
        if (result.code === 200) commit('GET_BANNER_LIST', result.data);
    },

    async getFloorList({
        commit
    }) {
        let result = await reqGetFloorList();
        if (result.code === 200) commit('GET_FLOOR_LIST', result.data);
    }
}

const mutations = {
    //三级导航栏列表
    REQ_CATEGORY_LIST(state, value) {
        state.categoryList = value
    },

    //banner图片
    GET_BANNER_LIST(state, value) {
        state.bannerList = value;
    },

    //floor数据
    GET_FLOOR_LIST(state, value) {
        state.floorList = value;
    }
}

const state = {
    //三级导航列表
    categoryList: [],
    bannerList: [],
    floorList: []
}

const getters = {
    //返回三级导航列表
    getCategoryList() {
        return state.categoryList;
    },
    //返回轮播图信息
    bannerList() {
        return state.bannerList;
    },
    //返回floor信息
    floorList() {
        return state.floorList;
    }
}

export default {
    actions,
    mutations,
    state,
    getters
}